package com.knowswift.security.handler.fail;

import com.knowswift.common.common.BaseResponse;
import com.knowswift.security.handler.JsonResponseHandler;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class CodeLoginFailureHandler extends JsonResponseHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) {
        int failCode = e.getMessage().contains("请求异常") ? BaseResponse.WECHAT_AUTH_FAIL : BaseResponse.FAIL_CODE;
        sendResponse(httpServletResponse, failCode, e.getMessage(), null);
    }
}
